package cn.geminis.auth.model;

import cn.geminis.lowcode.annotation.CrudRepository;
import cn.geminis.lowcode.annotation.QueryFilter;
import cn.geminis.lowcode.annotation.QueryFilterProperty;
import cn.geminis.lowcode.annotation.UuidEntity;
import jakarta.persistence.Column;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import lombok.*;

import java.time.LocalDateTime;

/**
 * @author puddi
 */
@Getter
@Setter
@UuidEntity(prePersist = false)
@QueryFilter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@CrudRepository
public class UserPassword {

    @Column(nullable = false, length = 32)
    @QueryFilterProperty
    private String username;

    @Column(nullable = false)
    private LocalDateTime passwordChangeTime;

    @Column(nullable = false, length = 256)
    private String password;

    @Column(length = 256)
    private String password2;

    @Column(length = 256)
    private String password3;

    @PrePersist
    @PreUpdate
    void updateChangeTime() {
        this.setId();
        passwordChangeTime = LocalDateTime.now();
    }
}
